package cc.mango.android.chartview;

import cc.telecomdigital.tdstock.Framework.UniqueItem.TDStockLog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.view.SurfaceHolder;
import android.view.View;

public abstract class BaseView extends View
{

	/** The view bounds. */
	protected int					width;
	protected int					height;

	//bottom size
	protected int					bottomHeight;
	//left size
	protected int					leftWidth;
	//right size
	protected int					rightWidth;
	//top size
	protected int					topHeight;

	protected Bitmap				bm;

	protected float				angle;

	protected int					bmWidth			= 35;
	protected int					bmHeight			= 35;

	protected boolean				stopFlag			= false;

	protected float				x;

	protected float				y;

	protected SurfaceHolder			holder;

	protected boolean				isShowBackground	= true;

	protected Paint				paint/* = new Paint()*/;
	protected PaintFlagsDrawFilter	pfd;

	private boolean				isScaleTooSmall	= false;

	public BaseView(Context context, Bitmap bm)
	{
		super(context);
		// TODO Auto-generated constructor stub
		paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG
				| Paint.DITHER_FLAG);
		paint.setAntiAlias(true); //modified by haibo, 2011-06-13, 图片抗锯齿效果
		pfd = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG
				| Paint.FILTER_BITMAP_FLAG); //modified by haibo, 2011-06-13, 图片抗锯齿效果
		TDStockLog.d("Print_Info", "width: " + bm.getWidth() + "Height: "
				+ bm.getHeight() + "");

		this.bm = bm;

	}

	@Override
	protected void onSizeChanged(int w, int h, int oldw, int oldh)
	{
		super.onSizeChanged(w, h, oldw, oldh);
		changeSize(w, h);

		TDStockLog.d("SunFlower", "sunflowerview   w:" + w + "  	h:" + h);
	}

	protected abstract void initSize(int width, int height);

	public void refresh()
	{

		if (isScaleTooSmall)
		{//scale小于0时，不绘制

			return;
		}

		postInvalidate();

	}

	protected void changeSize(int width, int height)
	{

		this.width = width;

		this.height = height;

		initSize(width, height);

		x = leftWidth + (width - leftWidth - rightWidth) / 2.0f;

		y = topHeight + (height - topHeight - bottomHeight) / 2.0f;

		bmWidth = width / 16;

		if (bmWidth <= 0)
		{

			isScaleTooSmall = true;

			return;
		}
		else
		{

			isScaleTooSmall = false;
		}

		bmHeight = bmWidth;

		Bitmap temp = bm;

		this.bm = Bitmap.createScaledBitmap(temp, bmWidth, bmHeight, true);

	}

	public void setIsShowBackground(boolean b)
	{

		this.isShowBackground = b;

	}

}
